package com.wxtt.android.fragment;

import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.fast.dev.frame.Adapter.listview.BaseListAdapter;
import com.fast.dev.frame.bean.I_Model;
import com.wxtt.android.R;
import com.wxtt.android.common.CommonFragment;
import com.wxtt.android.view.SwipeRefresh;
import com.wxtt.android.widget.EmptyBridge;

/**
 * 说明：BaseListFragment
 * <p/>
 * 作者：fanly
 * <p/>
 * 时间：2016/1/8 10:21
 * <p/>
 * 版本：verson 1.0
 */
public abstract class BaseListFragment<Bean extends I_Model> extends CommonFragment implements SwipeRefresh.RefreshListener, AdapterView.OnItemClickListener {

    protected ListView lv;
    protected EmptyBridge empty_bridge;
    //下拉刷新
    protected SwipeRefresh swipe_refresh;
    //设置Adapter
    protected BaseListAdapter<Bean> mAdapter;

    @Override
    protected int setRootView() {
        return R.layout.fragment_baselist;
    }

    @Override
    protected void onInit(View view) {
        super.onInit(view);
        //初始化控件
        initWidght();
        //初始化下拉刷新组件
        initSwipeRefresh();
        lv.setOnItemClickListener(this);
        if (mAdapter == null){
            mAdapter = setAdapter();
        }
        lv.setAdapter(mAdapter);
    }

    /**
     * 说明：初始化下拉刷新组件
     */
    private void initSwipeRefresh() {
        swipe_refresh.setRefreshListener(this);
    }

    /**
     * 说明：初始化控件
     */
    private void initWidght(){
        empty_bridge = bind(R.id.empty_bridge);
        lv = bind(R.id.lv);
        swipe_refresh = bind(R.id.swipe_refresh);
    }

    /**
     * 说明：获取数据
     * @return
     */
    public abstract BaseListAdapter<Bean> setAdapter();


}
